package com.wlient.springboot_stomp.controller;

import com.wlient.springboot_stomp.pojo.Message;
import com.wlient.springboot_stomp.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author JCccc
 * @Description
 * @Date 2021/8/20 8:53
 */
@Controller
public class TestController {
    @Autowired
    public SimpMessagingTemplate template;

    @Autowired
    public TestService testService;
 
    /**
     * 广播
     *
     * @param msg
     */
    @ResponseBody
    @RequestMapping("/pushToAll")
    public void sendMessge( @RequestBody Message msg) {
        template.convertAndSend("/topic/all", msg.getContent());
    }

    @RequestMapping("/oneToMore")
    public String oneToMore(){
        return "oneToMore.html";
    }

    @RequestMapping("/p2p")
    public String html(){
        return "p2p.html";
    }
}